import {requestData} from '../requestTool/index'

function Statistical(type) {
  var stratTime = wx.getStorageSync('StatisticalStartTime')
  let nowTime = new Date().getTime()
  let stay_time = Math.ceil((nowTime - stratTime)/1000)
  // let jscode = wx.getStorageSync('userJS_code')
  let params = {
    html_or_goods: type || 'html',
    jscode: '',
    stay_time: stay_time,
  }
  wx.login({
    success(res) {
        if (res.code) {
          params.jscode = res.code
        }
        requestData('userstatistics/',{
          data: JSON.stringify(params),
          methods:'POST'
        })
    }
  })
  wx.setStorageSync('StatisticalStartTime',nowTime)
}

module.exports = {
  Statistical: Statistical
}